package com.cloudkinto.service.platform.vo.rakuten;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

@Data
public class SenderModelEntity {
    /**
     * firstNameKana : カズヤ
     * firstName : 和也
     * zipCode1 : 038
     * subAddress : 唐牛字戸井頭36-2
     * zipCode2 : 0204
     * prefecture : 青森県
     * city : 南津軽郡大鰐町
     * familyName : 佐々木
     * phoneNumber1 : 090
     * phoneNumber2 : 6252
     * familyNameKana : ササキ
     * phoneNumber3 : 1348
     */
    private String firstNameKana;
    private String firstName;
    private String zipCode1;
    private String subAddress;
    private String zipCode2;
    private String prefecture;
    private String city;
    private String familyName;
    private String phoneNumber1;
    private String phoneNumber2;
    private String familyNameKana;
    private String phoneNumber3;


    public String getSenderName() {
        StringBuilder builder = new StringBuilder();
        if (StringUtils.isNotBlank(firstName) && StringUtils.isNotBlank(familyName)) {
            builder.append(familyName).append(" ").append(firstName);
        }
        else if (StringUtils.isNotBlank(firstNameKana) && StringUtils.isNotBlank(familyNameKana)) {
            builder.append(familyNameKana).append(" ").append(firstNameKana);
        }
        else {
            return StringUtils.isNotBlank(firstName) ? firstName : familyName;
        }
        return builder.toString();
    }

    public String getPhoneNumber() {
        StringBuilder builder = new StringBuilder();
        if (StringUtils.isNotBlank(phoneNumber1)) {
            if (builder.length() > 0) {
                builder.append("-");
            }
            builder.append(phoneNumber1);
        }
        if (StringUtils.isNotBlank(phoneNumber2)) {
            if (builder.length() > 0) {
                builder.append("-");
            }
            builder.append(phoneNumber2);
        }
        if (StringUtils.isNotBlank(phoneNumber3)) {
            if (builder.length() > 0) {
                builder.append("-");
            }
            builder.append(phoneNumber3);
        }
        return builder.toString();
    }


    public String getZipCode() {
        StringBuilder builder = new StringBuilder();
        if (StringUtils.isNotBlank(zipCode1)) {
            if (builder.length() > 0) {
                builder.append("-");
            }
            builder.append(zipCode1);
        }
        if (StringUtils.isNotBlank(zipCode2)) {
            if (builder.length() > 0) {
                builder.append("-");
            }
            builder.append(zipCode2);
        }

        return builder.toString();
    }

}
